package model

import (
	"gorm.io/gorm"
)

type AccountLog struct {
	gorm.Model
	UserID   int64  `gorm:"index;comment:Q号"`
	Username string `gorm:"comment:Q昵称"`
	Coins    int64  `gorm:"default:0;comment:当前金币"`
	Remarks  string `gorm:"comment:用途"`
}

func AddAccountLogData(data *AccountLog) {
	mysqlDb.Create(&data)
}

func AddAccountLogByUserID(userID int64, coins int64, remarks string) {
	AddAccountLogData(&AccountLog{
		UserID:  userID,
		Coins:   coins,
		Remarks: remarks,
	})
}

func GetAccountLogByUserID(userID int64) (accountLog []AccountLog) {
	accountLog = []AccountLog{}
	mysqlDb.Where(&AccountLog{
		UserID: userID,
	}).Order("created_at DESC").Limit(20).Find(&accountLog)
	return
}
